import {
    Inject,
    Controller,
    Get,
    Query,
    Post,
    Body,
    Del,
    Param,
} from '@midwayjs/core';
import { Context } from '@midwayjs/koa';
import { SellerService } from '../service/seller.service';
import { SellerAddDto, SellerPageQueryDto } from '../dto/seller.dto';
@Controller('/auth-api')
export class UserController {
    @Inject()
    ctx: Context;

    @Inject()
    sellerService: SellerService;

    /**
     * 注册经销商
     * @param body 
     * @returns 
     */
    @Post('/seller')
    public async addSeller(
        @Body()
        body: SellerAddDto
    ) {
        return this.sellerService.addSeller(body);
    }

    /**
     * 删除经销商
     * @param sellerId 经销商ID
     * @returns 
     */
    @Del('/seller/:id')
    public async deleteSeller(
        @Param('id')
        sellerId: number
    ) {
        return this.sellerService.deleteSeller(sellerId);
    }

    /**
     * 启用经销商
     * @param sellerId 经销商ID
     * @returns 
     */
    @Post('/seller/:id/enable')
    public async enableSeller(
        @Param('id')
        sellerId: number
    ) {
        return this.sellerService.enableSeller(sellerId);
    }

    /**
     * 禁用经销商
     * @param sellerId 经销商ID
     * @returns 
     */
    @Post('/seller/:id/disable')
    public async disableSeller(
        @Param('id')
        sellerId: number
    ) {
        return this.sellerService.disableSeller(sellerId);
    }

    /**
     * 查询经销商列表
     * @param query 
     * @returns 
     */
    @Get('/seller/list')
    public async getSellerList(
        @Query()
        query: Pick<SellerPageQueryDto, 'name' | 'phone' | 'status' | 'province'>
    ) {
        return this.sellerService.listSeller(query);
    }


    /**
     * 获取经销商分页列表
     * @param query 
     * @returns 
     */
    @Get('/seller/list/page')
    public async getSellerPageList(
        @Query()
        query: SellerPageQueryDto
    ) {
        return this.sellerService.pageListSeller(query);
    }
}
